<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>个人客户</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css" />
    <link
      href="../../../bstable/css/bootstrap.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../bstable/css/bootstrap-table.css"
      rel="stylesheet"
      type="text/css"
    />
  </head>

  <body>
    <div class="tabe_div">
      <p
        class="p_line text_ient"
        style="margin-bottom: -10px; border-bottom: 0"
      >
        <a class="find_a">姓名：</a>
        <input
          type="text"
          id="studentName"
          class="form_input text_ient"
          placeholder="输入姓名"
        />
        <a class="find_a">客户类型：</a>
        <select class="form_select" style="padding-left: 1%" id="customType">
          <option value="">请选择</option>
          <option value="1">一般客户</option>
          <option value="2">意向客户</option>
          <option value="3">成交客户</option>
          <option value="0">其他</option>
        </select>
        <a class="find_a">创建时间：</a>
        <input
          id="insertTime"
          type="date"
          class="input-70 form_input text_ient"
          placeholder=""
        />
        <a class="find_a">意向报考类型：</a>
        <select class="form_select" style="padding-left: 1%" id="preType">
          <option value="">请选择</option>
          <option value="1">学历提升</option>
          <option value="2">职业技能</option>
          <option value="3">职称评审</option>
          <option value="4">执业资格</option>
        </select>
        <input type="button" value="查询" class="but_find" id="search" />
      </p>
      <p class="p_line text_ient" style="margin-bottom: -10px">
        <input type="button" value="领取客户" class="but_find" id="getClient" />
      </p>
      <table
        data-url="json/data_alae_list.json"
        id="table"
        class="table_style"
        style="margin: 20px auto"
      ></table>
    </div>
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/laydate-master/laydate.js"></script>
    <script src="../../../bstable/js/bootstrap.min.js"></script>
    <script src="../../../bstable/js/bootstrap-table.js"></script>
    <script src="../../../bstable/js/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript">
      localStorage.setItem('name', '客户管理/公海客户');
      var pageNumber =
        location.search == '' ? 0 : location.search.split('=')[1];
      $(function () {
        openMsg();
        $('#search').on('click', function () {
          $('#table').bootstrapTable('refresh');
        });
        $('#getClient').on('click', function () {
          const selects = $('#table')
            .bootstrapTable('getSelections')
            .map((item) => {
              return item.id;
            });
          const id = selects.toString();

          console.log(`baseUrl`, baseUrl);

          // $.ajax({
          //   url: `${baseUrl}preStudent/toPrivate?id=${id}`,
          //   method: 'get',
          //   headers: {
          //     Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
          //   },
          //   success: function (data) {
          //     $('#table').bootstrapTable('refresh');
          //     alert('领取成功');
          //   },
          // });
        });
        var perm = JSON.parse(localStorage.getItem('userInfo')).perm;
        $('#table').bootstrapTable({
          method: 'get',
          striped: true,
          singleSelect: false,
          url: baseUrl + 'preStudent/getPublic',
          dataType: 'json',
          pagination: true, //分页
          sidePagination: 'server',
          pageSize: 10,
          pageNumber: Number(pageNumber) + 1,
          search: false, //显示搜索框
          contentType: 'application/x-www-form-urlencoded',
          ajaxOptions: {
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
          },
          queryParams: function (params) {
            params.studentName = $('#studentName').val();
            params.customType = $('#customType').val();
            params.insertTime = $('#insertTime').val();
            params.preType = $('#preType').val();
            params.offset = params.offset / params.limit;
            pageNumber = params.offset;
            delete params.order;
            return params;
          },
          responseHandler: function (res) {
            var list = res.data.records;
            return {
              rows: list,
              total: res.data.total,
            };
          },
          columns: [
            {
              checkbox: true,
              width: 80,
            },
            {
              field: 'no',
              title: '序号',
              sortable: true,
              align: 'center',
              formatter: function (value, row, index) {
                var pageSize =
                  $('#table').bootstrapTable('getOptions').pageSize;
                var pageNumber =
                  $('#table').bootstrapTable('getOptions').pageNumber;
                return pageSize * (pageNumber - 1) + index + 1;
              },
            },
            {
              title: '姓名',
              field: 'studentName',
              align: 'center',
              valign: 'middle',
            },
            {
              title: '跟进人',
              field: 'teacherName',
              align: 'center',
            },
            {
              title: '意向报考类型',
              field: 'preType',
              formatter: function (value, row, index) {
                switch (value) {
                  case '1':
                    return '学历提升';
                  case '2':
                    return '职业技能';
                  case '3':
                    return '职称评审';
                  case '4':
                    return '执业资格';
                }
              },
              align: 'center',
            },
            {
              title: '客户创建时间',
              field: 'insertTime',
              align: 'center',
            },
            {
              title: '客户类型',
              field: 'customType',
              formatter: function (value, row, index) {
                switch (value) {
                  case '1':
                    return '一般客户';
                  case '2':
                    return '意向客户';
                  case '3':
                    return '成交客户';
                  case '0':
                    return '其他';
                }
              },
              align: 'center',
            },
            {
              title: '最后修改时间',
              field: 'updateTime',
              align: 'center',
            },
            {
              title: '操作',
              field: 'id',
              align: 'center',
              width: '200',
              formatter: function (value, row) {
                var a =
                  '<a href="#" onclick="look(\'' + row.id + '\')">查看</a> ';

                return a;
              },
            },
          ],
        });
      });

      function look(id, idNo, flag, trainType, studyId, commitFlag) {
        window.location.href = `../student/customer-form.html?id=${id}&backName=common&isLook=look`;
      }
    </script>
  </body>
</html>
